home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / ex / checkdisk4.c < prev    next >
C/C++ Source or Header  |  1987-02-16  |  2KB  |  84 lines

  1. /* checkdisk.c */
  2.  
  3. #include "devices/trackdisk.h"
  4.  
  5. #define BLOCKSIZE TD_SECTOR
  6. #define CYLSIZE      (NUMHEADS * TD_SECTOR * NUMSECS)
  7. #define MEMF_CHIP (1L<<1)
  8.  
  9. unsigned char *diskbuffer;
  10. long td_open_error = -1;
  11.  
  12. struct MsgPort *diskport;
  13. struct IOExtTD *diskreq;
  14.  
  15. extern struct MsgPort *CreatePort();
  16. extern struct IORequest *CreateExtIO();
  17.  
  18. void MotorOnOff(onoff)    /* TURN DISK MOTOR ON/OFF */
  19. long onoff;
  20. {
  21.  diskreq->iotd_Req.io_Length = onoff;
  22.  diskreq->iotd_Req.io_Command = TD_MOTOR;
  23.  DoIO(diskreq);
  24. }
  25.  
  26.  
  27. main(argc,argv)
  28. int argc;
  29. char *argv[];
  30. {
  31. long unit, offset;
  32.  
  33. if (argc>1)
  34. {
  35.  unit = atoi(argv[1]);
  36.  if( unit < 0 || unit > 3) exit(0);
  37. }
  38. else
  39.  unit = 1;
  40.  
  41. if((diskbuffer = AllocMem(CYLSIZE,MEMF_CHIP))==0) cleanup();
  42.     
  43. if((diskport = CreatePort(0,0)) == 0) cleanup();
  44. /* make an io request block for communicating with the disk */
  45. if((diskreq = (struct IOExtTD *)CreateExtIO(diskport, sizeof(struct IOExtTD)))== 0)
  46.     cleanup();    
  47.  
  48. if(td_open_error = OpenDevice(TD_NAME,unit,diskreq,0)) cleanup();
  49.  
  50. MotorOnOff(1); /* Motor On */
  51.  
  52. for(offset=0;offset<CYLSIZE*NUMCYLS;offset+=CYLSIZE)    
  53. {
  54.    diskreq->iotd_Req.io_Flags = 0;      
  55.    diskreq->iotd_Req.io_Length = CYLSIZE;      
  56.    diskreq->iotd_Req.io_Data = (APTR)diskbuffer;    
  57.    diskreq->iotd_Req.io_Offset = offset; /* type long */
  58.    diskreq->iotd_Req.io_Command = ETD_READ;
  59.         /* check that disk not changed before reading */
  60.    diskreq->iotd_Count = 0xFFFFFFFF;
  61.    diskreq->iotd_SecLabel = 0;        
  62.     
  63.    DoIO(diskreq);
  64.  
  65.    if(diskreq->iotd_Req.io_Error != 0) 
  66.    printf("\nError %ld at Cylinder %ld.",
  67.     diskreq->iotd_Req.io_Error,
  68.         offset/(CYLSIZE) );
  69. }
  70. MotorOnOff(0);
  71.  
  72. cleanup();
  73. }    /* end of main */
  74.  
  75. cleanup()
  76. {
  77. if(diskbuffer) FreeMem(diskbuffer,BLOCKSIZE);
  78. if(!td_open_error) CloseDevice(diskreq);
  79. if(diskreq) DeleteExtIO(diskreq, sizeof(struct IOExtTD));
  80. if(diskport) DeletePort(diskport);
  81. exit(0);
  82. }
  83.  
  84.